﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OrganizacijeSeznam.aspx.cs"
    Inherits="Sio.Mdm.Web.Instalacija.OrganizacijeSeznam" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>SIO - MDM :: Instalacija : Seznam organizacij</title>
    <ext:XScript ID="XScript1" runat="server">
  <script type="text/javascript">
    var dodajZapis = function () {
      var grid = #{GridOrganizacijeSeznam};
      grid.getRowEditor().stopEditing();    
      grid.insertRecord(0, {
          OrganizacijaId: -99,
			    Naziv   : ""
      });
      
      grid.getView().refresh();
      grid.getSelectionModel().selectRow(0);
      grid.getRowEditor().startEditing(0);
    }
    
    var osveziOrg = function ()
    {
        #{StoreOrganizacijeSeznam}.reload();
    }
    
  var obcineRenderer = function (value) {					
			var r = StoreObcine.getById(value);
      if (Ext.isEmpty(r)) { return ""; }
      return r.data.Naziv;
  };
  var tipiOrganizacijRenderer = function (value) {					
			var r = StoreTipiOrganizacij.getById(value);
      if (Ext.isEmpty(r)) { return ""; }
      return r.data.Naziv;
  };
  var kategorijeZavodovRenderer = function (value) {					
			var r = StoreKategorijeZavodov.getById(value);
      if (Ext.isEmpty(r)) { return ""; }
      return r.data.Naziv;
  };
	var zdravstveniDomoviRenderer = function (value) {					
			var r = StoreZdravstveniDomovi.getById(value);
      if (Ext.isEmpty(r)) { return ""; }
      return r.data.Naziv;
  };

</script>
    </ext:XScript>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:Store ID="StoreObcine" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="ObcinaId">
                <Fields>
                    <ext:RecordField Name="ObcinaId" Type="Int" />
                    <ext:RecordField Name="Naziv" Type="String" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="StoreTipiOrganizacij" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="TipOrganizacijeId">
                <Fields>
                    <ext:RecordField Name="TipOrganizacijeId" Type="Int" />
                    <ext:RecordField Name="Naziv" Type="String" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="StoreKategorijeZavodov" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="KategorijaZavodaId">
                <Fields>
                    <ext:RecordField Name="KategorijaZavodaId" Type="Int" />
                    <ext:RecordField Name="Naziv" Type="String" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="StoreZdravstveniDomovi" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="ZdravstveniDomId">
                <Fields>
                    <ext:RecordField Name="ZdravstveniDomId" Type="Int" />
                    <ext:RecordField Name="Naziv" Type="String" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server" Layout="Fit">
        <Content>
            <sio:GridPanel ID="GridOrganizacijeSeznam" runat="server" StripeRows="true" TrackMouseOver="true">
                <Plugins>
                    <ext:RowEditor ID="RowEditor1" runat="server" SaveText="Shrani" CancelText="Prekliči" ClicksToEdit="2">
                        <DirectEvents>
                            <AfterEdit OnEvent="UrediPodatke">
                                <ExtraParams>
                                    <ext:Parameter Mode="Raw" Name="data" Value="r.data" />
                                </ExtraParams>
                            </AfterEdit>
                        </DirectEvents>
                    </ext:RowEditor>
                    <ext:GridFilters ID="GridFilters1" runat="server">
                        <Filters>
                            <ext:NumericFilter DataIndex="OrganizacijaId" />
                            <ext:StringFilter DataIndex="Naziv" />
                        </Filters>
                    </ext:GridFilters>
                </Plugins>
                <Store>
                    <ext:Store ID="StoreOrganizacijeSeznam" runat="server">
                        <SortInfo Field="Naziv" />
                        <Reader>
                            <ext:JsonReader IDProperty="OrganizacijaId">
                                <Fields>
                                    <ext:RecordField Name="OrganizacijaId" Type="Int" />
                                    <ext:RecordField Name="Naziv" Type="String" />
                                    <ext:RecordField Name="DavcnaStevilka" Type="Int" />
                                    <ext:RecordField Name="ObcinaId" Type="Int" />
                                    <ext:RecordField Name="TipOrganizacijeId" Type="Int" />
                                    <ext:RecordField Name="KategorijaZavodaId" Type="Int" />
                                    <ext:RecordField Name="ZdravstveniDomId" Type="Int" />
                                    <ext:RecordField Name="Aktivno" Type="Boolean" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column ColumnID="OrganizacijaId" Hidden="true" Hideable="false" DataIndex="OrganizacijaId">
                        </ext:Column>
                        <ext:Column Header="Tip organizacije" DataIndex="TipOrganizacijeId" Width="150">
                            <Renderer Fn="tipiOrganizacijRenderer" />
                            <Editor>
                                <ext:ComboBox ID="ComboBox1" runat="server" TypeAhead="true" SelectOnFocus="true"
                                    Editable="true" Mode="Local" ForceSelection="true" StoreID="StoreTipiOrganizacij"
                                    ValueField="TipOrganizacijeId" DisplayField="Naziv" AllowBlank="false" />
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="Naziv" Header="Naziv" DataIndex="Naziv" Width="150">
                            <Editor>
                                <ext:TextField runat="server" AllowBlank="false" MinLength="2" MinLengthText="Vpišite naziv organizacije"
                                    BlankText="Vpišite naziv organizacije" />
                            </Editor>
                        </ext:Column>
                        <ext:BooleanColumn Header="Aktivno" DataIndex="Aktivno" Width="50" TrueText="Da"
                            FalseText="Ne">
                            <Editor>
                                <ext:Checkbox runat="server" />
                            </Editor>                            
                        </ext:BooleanColumn>
                        <ext:Column ColumnID="Davcna" Header="Davčna številka" DataIndex="DavcnaStevilka"
                            Width="100">
                            <Editor>
                                <ext:NumberField ID="inputDs" runat="server" DataIndex="DavcnaStevilka" />
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Kategorija zavoda" DataIndex="KategorijaZavodaId" Width="100">
                            <Renderer Fn="kategorijeZavodovRenderer" />
                            <Editor>
                                <ext:ComboBox ID="ComboBox2" runat="server" TypeAhead="true" SelectOnFocus="true"
                                    Editable="true" Mode="Local" ForceSelection="true" StoreID="StoreKategorijeZavodov"
                                    ValueField="KategorijaZavodaId" DisplayField="Naziv" />
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Občina" DataIndex="ObcinaId" Width="150">
                            <Renderer Fn="obcineRenderer" />
                            <Editor>
                                <ext:ComboBox ID="ComboBox3" runat="server" TypeAhead="true" SelectOnFocus="true"
                                    Editable="true" Mode="Local" ForceSelection="true" StoreID="StoreObcine" ValueField="ObcinaId"
                                    DisplayField="Naziv" />
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Zdravstveni dom" DataIndex="ZdravstveniDomId" Width="150">
                            <Renderer Fn="zdravstveniDomoviRenderer" />
                            <Editor>
                                <ext:ComboBox ID="cbObcine" runat="server" TypeAhead="true" SelectOnFocus="true"
                                    Editable="true" Mode="Local" ForceSelection="true" StoreID="StoreZdravstveniDomovi"
                                    ValueField="ZdravstveniDomId" DisplayField="Naziv" />
                            </Editor>
                        </ext:Column>
                        <ext:CommandColumn Width="35">
                            <Commands>
                                <ext:GridCommand Icon="NoteEdit" CommandName="Uredi">
                                    <ToolTip Text="Uredi" />
                                </ext:GridCommand>
                            </Commands>
                        </ext:CommandColumn>
                    </Columns>
                </ColumnModel>
                <Listeners>
                    <Command Handler="openTab('OrganizacijaPodrobnosti.aspx', 'Organizacija '+record.data.Naziv, {OrganizacijaId: record.id }, 'OrganizacijaId'+record.id);" />
                </Listeners>
                <SelectionModel>
                    <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" />
                </SelectionModel>
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server" Width="500">
                        <Items>
                            <sio:Button ID="Button1" runat="server" Text="Dodaj" Icon="Add">
                                <Listeners>
                                    <Click Fn="dodajZapis" />
                                </Listeners>
                            </sio:Button>
                            <sio:Button ID="Button3" runat="server" Text="Briši" Icon="Delete">
                                <DirectEvents>
                                    <Click OnEvent="OdstraniZapise" After="#{StoreOrganizacijeSeznam}.reload();">
                                        <Confirmation ConfirmRequest="true" Message="Izbrišem izbrane organizacije?" />
                                        <ExtraParams>
                                            <ext:Parameter Name="selected" Mode="Raw" Value="Ext.encode(#{GridOrganizacijeSeznam}.getRowsValues({selectedOnly:true}))" />
                                        </ExtraParams>
                                    </Click>
                                </DirectEvents>
                            </sio:Button>
                            <sio:Button runat="server" Text="Osveži" Icon="ArrowRefresh">
                                <Listeners>
                                    <Click  Fn="osveziOrg" />
                                </Listeners>
                            </sio:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
            </sio:GridPanel>
        </Content>
    </ext:Viewport>
    </form>
</body>
</html>
